package com.sdl.timesblogmp.controller;


import com.sdl.timesblogmp.model.entity.Category;
import com.sdl.timesblogmp.model.vo.ApiResult;
import com.sdl.timesblogmp.model.vo.PageParam;
import com.sdl.timesblogmp.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sdl
 * @since 2020-05-11
 */
@Api(value = "分类接口", tags = "分类接口")
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    @ApiOperation(value = "获取所有分类")
    @GetMapping("/list")
    public ApiResult getallcategory( PageParam pageParam){
        return ApiResult.success( categoryService.findCategoryInfo(pageParam)) ;
    }
    @ApiOperation(value = "新增一个分类")
    @PostMapping("/add")
    public ApiResult addcategory(@RequestBody Category category){
        categoryService.save(category);
        return ApiResult.success();
    }
    @ApiOperation(value = "删除一个分类")
    @DeleteMapping("/del/{id}")
    public ApiResult deletecategory(@PathVariable Integer id){
        categoryService.delCategoru(id);
        return ApiResult.success();
    }
    @ApiOperation(value = "更新分类信息")
    @PutMapping("/update")
    public ApiResult updatecategory(@RequestBody Category category){
        categoryService.updateById(category);
        return ApiResult.success();
    }
}

